home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / actlib13.zip / TOOLS.ZIP / PASSWD.C < prev    next >
C/C++ Source or Header  |  1993-02-25  |  1KB  |  55 lines

  1. /*  Copyright (C) 1993   Marc Stern  (internet: stern@mble.philips.be)  */
  2.  
  3. #include "key.h"
  4. #include "tools.h"
  5. #include <conio.h>
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8.  
  9.  
  10.  
  11. /*
  12.  * Functions    : getPasswd
  13.  *
  14.  * Description  : Input a password (echoes '*')
  15.  *
  16.  * Parameters   : in  char *passwd    string to store password
  17.  *
  18.  * Remarks      : Backspace and left arrow can be used to erase characters
  19.  *                Characters must be in the range 32 - 254
  20.  *
  21.  * Return       : pointer to password
  22.  *
  23.  */
  24.  
  25. char *getPasswd( char *passwd )
  26.  
  27. { char *ptr = passwd;
  28.   int key;
  29.  
  30.   for (;;) { switch( key = getkey() )
  31.                    {
  32.                      case '\0':
  33.                      case '\n':
  34.                      case '\r':
  35.                      case EOF : putch( '\r' ); putch( '\n' );
  36.                                 *ptr = '\0';
  37.                                 return passwd;
  38.  
  39.                      case LEFT:
  40.                      case '\b': if ( ptr > passwd )
  41.                                    {
  42.                                      ptr--;
  43.                                      putch( '\b' );  putch( SPACE ); putch( '\b' );
  44.                                    }
  45.                                 continue;
  46.  
  47.                      default  : if ( key < 32 || key > 254 ) continue;
  48.  
  49.                                 putch( '*' );
  50.                                 break;
  51.                    }
  52.              *ptr++ = key;
  53.            }
  54. }
  55.